

import 'dart:convert';
import 'dart:io';

import 'package:flutter_elf/utils/get_utils.dart';
import 'package:uuid/uuid.dart';

import '../download/file_utils.dart';
import 'video_info_rsp.dart';

void main()async{
  int start = 10533;
//  File file = await FileUtils.createFile('test/Sunflower/urls.json');
  File file = await FileUtils.getFile('test/Sunflower/urls119.txt');
  print(file.path);
//  file.writeAsStringSync('==============',mode: FileMode.append);
//  file.writeAsStringSync('123\n',mode: FileMode.append);
//  file.writeAsStringSync('123\n',mode: FileMode.append);
  print('=======开始=======');
//  print(Uuid().v4().replaceAll('-', '').substring(0,16));
  String uuid = Uuid().v4().replaceAll('-', '').substring(0,16);
  for(int i = start;i < 10534;i++){
    if(i % 10 == 0){
      uuid = Uuid().v4().replaceAll('-', '').substring(0,16);
    }
    if(i % 500 == 0) {
//      file = await FileUtils.getFile('test/Sunflower/urls$i.txt');
    }
    VideoInfoRsp info = await getVideoInfo(i,uuid);
    if(info.code == 200){
      file.writeAsStringSync((info.toString()) + ',',mode: FileMode.append);
      file.writeAsStringSync('\n',mode: FileMode.append);
      Future.delayed(Duration(milliseconds: 50));
    }
  }
  await Future.delayed(Duration(seconds: 100000000));
}


Future<VideoInfoRsp> getVideoInfo(int id,String uuid)async{
  String result = await HttpUtils.get('http://hzpqub.com/api/videoplay/$id?uuid=$uuid&device=0');
  VideoInfoRsp rsp = VideoInfoRsp.fromJson(json.decode(result));
  print('id========>$id   uuid===========>$uuid        ' + rsp.toString());
  return rsp;
}